package com.mrd.gtimp.service.impl;

import com.mrd.constant.BaseTypeConstant;
import com.mrd.constant.BizProcessConstants;
import com.mrd.constant.MsgConstants;
import com.mrd.constant.SpecialConstant;
import com.mrd.framework.ui.Jqgrid;
import com.mrd.framework.ui.filter.Filter;
import com.mrd.framework.ui.filter.FilterGroupOption;
import com.mrd.framework.ui.filter.SearchRule;
import com.mrd.framework.ui.filter.SearchRuleOption;
import com.mrd.gtimp.base.service.itf.SysMsgSendBiz;
import com.mrd.gtimp.business.entity.Commodity;
import com.mrd.gtimp.business.entity.Declaration;
import com.mrd.gtimp.business.entity.DeclarationInform;
import com.mrd.gtimp.business.entity.RejectContent;
import com.mrd.gtimp.business.service.CommodityBiz;
import com.mrd.gtimp.business.service.DeclarationBiz;
import com.mrd.gtimp.business.service.DeclarationInformBiz;
import com.mrd.gtimp.business.service.DiDanAttachmentBiz;
import com.mrd.gtimp.business.service.InspectionGoodsBiz;
import com.mrd.gtimp.business.service.RejectContentBiz;
import com.mrd.gtimp.business.service.SuiFuDanBiz;
import com.mrd.gtimp.order.service.DeclaContainerBiz;
import com.mrd.gtimp.service.IDeclarationBizService;
import com.mrd.gtimp.service.dto.GtimpBaseBizQueryDTO;
import com.mrd.gtimp.service.dto.GtimpDeclarationBizQueryDTO;
import com.mrd.gtimp.service.dto.GtimpTrailBizQueryDTO;
import com.mrd.util.DownloadPropertiesUtil;
import com.mrd.util.ReflectUtil;
import com.mrd.util.service.JSONObjectBuilder;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.jws.WebService;

@WebService(endpointInterface = "com.mrd.gtimp.service.IDeclarationBizService",
        serviceName = "DeclarationBizService")
@Component
public class DeclarationBizServiceImpl implements IDeclarationBizService {

    @Resource
    private DeclarationBiz declarationBiz;
    @Resource
    private DeclarationInformBiz declarationInformBiz;
    private String msg;
    @Resource
    private SysMsgSendBiz sysMsgSendBiz;
    @Resource
    private RejectContentBiz rejectContentBiz;
    @Resource
    private CommodityBiz commodityBiz;
    @Resource
    private SuiFuDanBiz suiFuDanBiz;
    @Resource
    private DeclaContainerBiz declaContainerBiz;
    @Resource
    private DiDanAttachmentBiz diDanAttachmentBiz;
    @Resource
    private InspectionGoodsBiz inspectionGoodsBiz;

    @Override
    public String findListForSupToValidate(String paramsJson) throws Exception {
        try {

            List<Declaration> declarations = new ArrayList<Declaration>();

            // 预期的查询字段
            // size,pageNo,sidx,sord,filters
            GtimpDeclarationBizQueryDTO qdto = (GtimpDeclarationBizQueryDTO) JSONObject
                    .toBean(JSONObject.fromObject(paramsJson), GtimpDeclarationBizQueryDTO.class);

            String comId = qdto.getSupId();
            Filter filters = new Filter();
            filters.setGroupOp(FilterGroupOption.AND);
            // 20131114修改
            // SearchRule rule = new SearchRule("supCompany.id", SearchRuleOption.eq, comId);
            // filters.addRule(rule);
            SearchRule rule2 = new SearchRule("state", SearchRuleOption.nc, BaseTypeConstant.DECLARATIONSTATE_00);
            filters.addRule(rule2);
            SearchRule rule3 = new SearchRule("state", SearchRuleOption.nc, BaseTypeConstant.DECLARATIONSTATE_01);
            filters.addRule(rule3);
            SearchRule rule4 = new SearchRule("state", SearchRuleOption.nc, BaseTypeConstant.DECLARATIONSTATE_03);
            filters.addRule(rule4);
            SearchRule rule5 = new SearchRule("state", SearchRuleOption.nc, "DS030");
            filters.addRule(rule5);

            Pageable pageable = qdto.getPage() == null ? new PageRequest(1, 15)
                    : new PageRequest(qdto.getPage().getCurrentPage(), qdto.getPage()
                    .getPageSize());
            Jqgrid jqgrid = new Jqgrid(filters, pageable);
            jqgrid.addOrder("ASC".equalsIgnoreCase(qdto.getSord()) ? Sort.Direction.ASC
                    : Sort.Direction.DESC, StringUtils.isEmpty(qdto.getSidx()) ? "confirmTime"
                    : qdto.getSidx());

            JSONArray array = JSONArray.fromObject(qdto.getRules());
            for (int i = 0; i < array.size(); i++) {
                JSONObject object = (JSONObject) array.get(i);
                SearchRule rule = (SearchRule) JSONObject.toBean(object, SearchRule.class);
                filters.addRule(rule);
            }

            String listCase = "select sval.chn, declaration from com.mrd.gtimp.business.entity.Declaration declaration, com.mrd.gtimp.base.entity.SystemValue sval where declaration.state=sval.identifier ";
            String whereCase = "";
            whereCase += "and (declaration.realSupId = '" + comId
                    + "'  or (declaration.supCompany = '" + comId
                    + "' and declaration.realSupId is null))";
            if (null != filters.getRules() && filters.getRules().size() > 0) {
                for (SearchRule sr : filters.getRules()) {
                    String field = sr.getField();
                    Object data = sr.getData();
                    Field f = ReflectUtil.getField(sr.getField(), Declaration.class);
                    boolean isDate = false;
                    if (f != null) {
                        if (f.getType().equals(Date.class)) {
                            data = "to_date('" + data + "','yyyy-MM-dd')";
                            isDate = true;
                        }
                    }
                    if (sr.getOp() == SearchRuleOption.eq) {
                        whereCase = whereCase + " and declaration." + field + " = '" + data + "' ";
                    } else if (sr.getOp() == SearchRuleOption.nc) {
                        whereCase = whereCase + " and declaration." + field + " not in ('" + data
                                + "') ";
                    } else if (sr.getOp().equals(SearchRuleOption.gt)) {
                        whereCase = whereCase + " and declaration." + field
                                + (isDate ? " > " + data : " > '" + data + "'");
                    } else if (sr.getOp().equals(SearchRuleOption.lt)) {
                        whereCase = whereCase + " and declaration." + field
                                + (isDate ? " < " + data : " < '" + data + "'");
                    } else if (sr.getOp().equals(SearchRuleOption.ge)) {
                        whereCase = whereCase + " and declaration." + field
                                + (isDate ? " >= " + data : " >= '" + data + "'");
                    } else if (sr.getOp().equals(SearchRuleOption.le)) {
                        whereCase = whereCase + " and declaration." + field
                                + (isDate ? " <= " + data : " <= '" + data + "'");
                    } else {
                        whereCase = whereCase + " and declaration." + field + " like '%" + data
                                + "%' ";
                    }
                }
            }
            whereCase = whereCase + " order by declaration." + jqgrid.getOrder().getProperty() + " "
                    + jqgrid.getOrder().getDirection().toString() + " ";
            listCase = listCase + whereCase;
            List<Object> objList = declarationBiz.findObjectByHql(listCase, jqgrid.getPage()
                    .getPageNumber(), jqgrid.getPage().getPageSize(), null);
            int count = declarationBiz.findEntityCountByHql("select count(*) "
                    + listCase.substring(listCase.indexOf("from")), null);

            if (null != objList && objList.size() > 0) {
                for (Object o : objList) {
                    Object[] os = (Object[]) o;
                    Declaration b = (Declaration) os[1];
                    b.setDecState(SpecialConstant.VALIDATE_STATE_CUSTOMER_VIEW
                            .equals(os[0].toString()) ? SpecialConstant.VALIDATE_STATE_SUP_VIEW
                            : os[0].toString());
                    declarations.add(b);
                }
            }

            // init result string
            JSONObject resultObj = new JSONObject();
            int totalPage = count % pageable.getPageSize() == 0 ? count / pageable.getPageSize()
                    : count / pageable.getPageSize() + 1;
            com.mrd.gtimp.service.dto.Page remotePage = new com.mrd.gtimp.service.dto.Page(jqgrid
                    .getPage().getPageNumber(), count, pageable.getPageSize(), totalPage);
            resultObj.put("page", remotePage);
            String configString = "id,confirmTime|D,VALIDATE_TIME|D,customer.id,customer.name,shipper.id,shipper.company,state,declarationInform.id,"
                    + "declarationInform.confirmState,businessId,company_name,contract_no,work_no,validator.name,declaration_type";
            JSONArray resultArray = JSONObjectBuilder
                    .objectListToJsonArray(declarations, configString);// new
            resultObj.put("declarations", resultArray);

            return resultObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    /**
     * 供应商报关资料发送提醒查看
     */
    @Override
    public String findForDeclarationInform(String paramsJson) throws Exception {
        DeclarationInform declarationInform = null;
        GtimpDeclarationBizQueryDTO qdto = (GtimpDeclarationBizQueryDTO) JSONObject
                .toBean(JSONObject.fromObject(paramsJson), GtimpDeclarationBizQueryDTO.class);
        String id = qdto.getId();
        declarationInform = declarationInformBiz.findEntityById(id);
        JSONObject resuJsonObj = new JSONObject();
        String declarationInformConfigString = "id,sendRemind.id,sendRemind.mailFileContents,"
                + "sendRemind.expressCompanyName,sendRemind.expressNo,sendRemind.remark";
        resuJsonObj.put("declarationInform", JSONObjectBuilder
                .objectToJsonObjectByConfig(declarationInform, declarationInformConfigString));
        return resuJsonObj.toString();
    }

    @Override
    public String findForSupToValidate(String paramsJson) throws Exception {
        Declaration declaration = null;
        GtimpDeclarationBizQueryDTO qdto = (GtimpDeclarationBizQueryDTO) JSONObject
                .toBean(JSONObject.fromObject(paramsJson), GtimpDeclarationBizQueryDTO.class);
        String id = qdto.getId();
        declaration = declarationBiz.findEntityById(id);

        List<Commodity> commodityList = commodityBiz.findByDeclaration(declaration);
        Collections.sort(commodityList, new Comparator<Commodity>() {
            public int compare(Commodity arg0, Commodity arg1) {
                String index_num_0 = arg0.getIndex_num();
                String index_num_1 = arg1.getIndex_num();
                return Integer.parseInt(index_num_0) > Integer.parseInt(index_num_1) ? 1 : -1;
            }
        });
        /*List<Commodity> nCommodities = new ArrayList<Commodity>();
        int index_num = 0;
        for (int i = 0; i < commodityList.size(); i++) {
            index_num = i + 1;
            Commodity c = commodityList.get(i);
            if ((index_num + "").equals(c.getIndex_num())) {
                nCommodities.add(c);
            }
        }*/
        declaration.setCommodities(commodityList);
        declaration.setSuiFuDans(suiFuDanBiz.findByDeclaration(declaration));
        declaration.setDeclaContainers(declaContainerBiz.findByDeclaration(declaration));
        declaration.setDiDans(diDanAttachmentBiz.findByDeclaration(declaration));
        declaration.setRejectContents(rejectContentBiz.findByDeclaration(declaration));
        declaration.setInspectionGoodsList(inspectionGoodsBiz.findByDeclaration(declaration));

        String url = "";
        if (declaration.getContainerInfo() != null) {
            url = DownloadPropertiesUtil.getDlNetAddress(declaration.getContainerInfo().getId());
            declaration.getContainerInfo().setDlUrl(url);
        }

		/*
         * RECORD_ID不为空，手册类型的报关单goods_mode商品规格可以给客户填写，但是信息不导入佛港系统。
		 */
        if (declaration.getRecord_id() != null && !declaration.getRecord_id().equals("")) {
            List<Commodity> commodities = declaration.getCommodities();
            for (int i = 0; i < commodities.size(); i++) {
                Commodity c = commodities.get(i);
                commodities.set(i, c);
            }
            declaration.setCommodities(commodities);
        }

        // init result string
        JSONObject resultObj = new JSONObject();
        String declarationConfigString = "id,confirmTime|D,VALIDATE_TIME|D,state,"
                + "customer.id,customer.name,customer.address,customer.phone,customer.fax,"
                + "shipper.id,shipper.name,shipper.address,shipper.phone,shipper.fax,"
                + "company_co,company_name,export_port,"
                + "trading_country,trading_country_code,special_relationship_confirm,price_impact_confirm,payment_royaltils_confirm,"
                + "record_id,contract_no,export_date|D,transport_mode,fahuo_company_co,fahuo_company_name,shenbao_company_co,shenbao_company_name,transport_na,voyage_no,"
                + "bl_no,trade_mode,levymode,lc_type,tex_company,license_no,arrived_country,arrived_port,goods_addr,approval_no,deal_mode,freight1,freight2,freight3,premium1,"
                + "premium2,premium3,otherfee1,otherfee2,otherfee3,goods_count,goods_package,gross_weight,net_weight,suifudan,customs_type,remark,"
                + "container_no,container_no_show,commodities|L.record_id,commodities|L.code_t,commodities|L.code_s,commodities|L.name,commodities|L.goods_mode,"
                + "commodities|L.count,commodities|L.unit,commodities|L.unit_price,commodities|L.total_price,commodities|L.currency,commodities|L.legal_count,"
                + "commodities|L.legal_unit,commodities|L.version_no,commodities|L.goods_no,commodities|L.producer,commodities|L.second_count,commodities|L.second_unit,"
                + "commodities|L.destination,commodities|L.levymode,commodities|L.processing_fee,commodities|L.origin_country,commodities|L.origin_country_code,commodities|L.handbook_item_no,"
                + "suiFuDans|L.suifudan_co,suiFuDans|L.suifudan_no,suiFuDans|L.suifudan_co_cn,declarationInform.id,containerInfo.id,containerInfo.dlUrl,containerInfo.name,declaration_type,commodities|L.contractNumber,"
                + "company_co_unite,fahuo_company_co_unite,re_manifest";
        resultObj.put("declaration", JSONObjectBuilder
                .objectToJsonObjectByConfig(declaration, declarationConfigString));
        System.out.println("resultObj.toString()========" + resultObj.toString());
        return resultObj.toString();
    }

    @Override
    public String validatePass(String paramsJson) throws Exception {
        Declaration declaration = null;
        GtimpDeclarationBizQueryDTO qdto = (GtimpDeclarationBizQueryDTO) JSONObject
                .toBean(JSONObject.fromObject(paramsJson), GtimpDeclarationBizQueryDTO.class);
        String id = qdto.getId();
        String validator = qdto.getUserAccount();
        declaration = declarationBiz.findEntityById(id);
        if (null != declaration
                && declaration.getDecState().equals(BaseTypeConstant.DECLARATIONSTATE_01)) {
            declarationBiz.updateValidatePass(id, validator);
            setMsg(MsgConstants.OPERATION_SUCCESS);
        } else {
            setMsg(MsgConstants.OPERATION_FAIL);
        }
        return getMsg();
    }

    @Override
    public String validateReject(String paramsJson) throws Exception {
        Declaration declaration = null;
        GtimpDeclarationBizQueryDTO qdto = (GtimpDeclarationBizQueryDTO) JSONObject
                .toBean(JSONObject.fromObject(paramsJson), GtimpDeclarationBizQueryDTO.class);
        String id = qdto.getId();
        String validator = qdto.getUserAccount();
        String rejectContent = qdto.getRejectContent();
        declaration = declarationBiz.findEntityById(id);
        if (null != declaration
                && declaration.getDecState().equals(BaseTypeConstant.DECLARATIONSTATE_01)) {
            RejectContent rc = new RejectContent();
            rc.setContent(rejectContent);
            rc.setRejectDate(new Date());
            rc.setRejectPerson(validator);
            // rc.setBid(id);
            // @2016-11-1 11:03 将rc.setBid(id)替换城以下三句句，因为已经不存在Bid属性
            Declaration declaration1 = new Declaration();
            declaration1.setId(id);
            rc.setDeclaration(declaration1);
            //
            declarationBiz.updateValidateReject(id, validator);
            rejectContentBiz.saveOrupdateEntity(rc);
            setMsg(MsgConstants.OPERATION_SUCCESS);
        } else {
            setMsg(MsgConstants.OPERATION_FAIL);
        }
        return getMsg();
    }

    @Override
    public String declarationStateTrack(String paramsJson) throws Exception {
        GtimpDeclarationBizQueryDTO qdto = (GtimpDeclarationBizQueryDTO) JSONObject
                .toBean(JSONObject.fromObject(paramsJson), GtimpDeclarationBizQueryDTO.class);
        String id = qdto.getId();
        String state = qdto.getDeclaration().getState();
        String validator = qdto.getUserAccount();
        declarationBiz.updateValidateDeclarationTrackState(id, validator, state);
        msg = MsgConstants.SAVE_SUECCES;
        return msg;
    }

    @Override
    public String insertDeclarationBiz(String paramsJson) throws Exception {
        GtimpDeclarationBizQueryDTO qdto = (GtimpDeclarationBizQueryDTO) JSONObject
                .toBean(JSONObject.fromObject(paramsJson), GtimpDeclarationBizQueryDTO.class);
        String bpk = qdto.getBpk();
        String id = qdto.getId();
        String validator = qdto.getUserAccount();
        Declaration d = new Declaration();
        d.setId(id);
        d.setBpk(bpk);

        d.setContract_no(qdto.getDeclaration().getContract_no());
        d.setSno(qdto.getDeclaration().getSno());
        d.setContainer_no(qdto.getDeclaration().getContainerStr());// 报关单关联的柜号
        d.setWork_no(qdto.getDeclaration().getWork_no());// 三联单流水号
//        List<String> properties = new ArrayList<String>();
//        properties.add("bpk");
//        properties.add("sno");
//        properties.add("contract_no");
//        properties.add("container_no");
//        properties.add("work_no");
//        declarationBiz.updateEntity(d, properties);
        declarationBiz.updateWorkNo(d);
        declarationBiz.updateValidateUpload(id, validator);
        msg = MsgConstants.SAVE_SUECCES;
        return msg;
    }

    @Override
    public String updateDeclarationBiz(String paramsJson) throws Exception {
        GtimpDeclarationBizQueryDTO qdto = (GtimpDeclarationBizQueryDTO) JSONObject
                .toBean(JSONObject.fromObject(paramsJson), GtimpDeclarationBizQueryDTO.class);
        String id = qdto.getId();
        Declaration d = new Declaration();
        d.setId(id);
        d.setSno(qdto.getDeclaration().getSno());
        d.setContract_no(qdto.getDeclaration().getContract_no());
        d.setContainer_no(qdto.getDeclaration().getContainerStr());
        List<String> properties = new ArrayList<String>();
        properties.add("sno");
        properties.add("contract_no");
        properties.add("container_no");
        declarationBiz.updateEntity(d, properties);
        msg = MsgConstants.SAVE_SUECCES;
        return msg;
    }

    @Override
    public String findDeclarationBizInfo(String paramsJson) throws Exception {
        return null;
    }

    public DeclarationBiz getDeclarationBiz() {
        return declarationBiz;
    }

    public void setDeclarationBiz(DeclarationBiz declarationBiz) {
        this.declarationBiz = declarationBiz;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    // @Override
    // public String validateUpload(String paramsJson) throws Exception {
    // return null;
    // }

    @Override
    public String validateFinish(String paramsJson) throws Exception {
        System.out.println("进入更新报关下单完成状态方法.................");
        System.out.println("更新报关下单完成状态paramsJson==========" + paramsJson);
        GtimpDeclarationBizQueryDTO qdto = (GtimpDeclarationBizQueryDTO) JSONObject
                .toBean(JSONObject.fromObject(paramsJson), GtimpDeclarationBizQueryDTO.class);
        String bpk = qdto.getBpk().trim();
        System.out.println(bpk);
        List<Object> list = new ArrayList<Object>();
        list = declarationBiz.findObjectBySql("select id from t_biz_declaration t where t.sno in ('"
                + bpk + "')", 0, 5, null);
        String id = list.get(0).toString();
        String validator = qdto.getUserAccount();
        // declaration = declarationBiz.findEntityById(id);
        // if(null != declaration
        // && declaration.getDecState().equals(BaseTypeConstant.DECLARATIONSTATE_04)) {
        // id = declaration.getId();
        System.out.println("id后========" + id);
        declarationBiz.updateValidateFinish(id, validator);
        setMsg(MsgConstants.OPERATION_SUCCESS);
        // } else {
        // setMsg(MsgConstants.OPERATION_FAIL);
        // }
        return getMsg();
    }

    @Override
    public String findDeclarationInformListForSup(GtimpBaseBizQueryDTO qdto) throws Exception {
        String comId = qdto.getSupId();
        Filter filters = new Filter();
        filters.setGroupOp(FilterGroupOption.AND);
        SearchRule rule = new SearchRule("supCompany.id", SearchRuleOption.eq, comId);
        filters.addRule(rule);
        // 为适应3.0框架 已修改
        Pageable pageable = qdto.getPage() == null ? new PageRequest(1, 15)
                : new PageRequest(qdto.getPage().getCurrentPage(), qdto.getPage().getPageSize());
        Jqgrid jqgrid = new Jqgrid(filters, pageable);
        jqgrid.addOrder("ASC".equalsIgnoreCase(qdto.getSord()) ? Sort.Direction.ASC
                : Sort.Direction.DESC, StringUtils.isEmpty(qdto.getSidx()) ? "createTime"
                : qdto.getSidx());

        Page<DeclarationInform> declarationInforms = declarationInformBiz.findByJqgrid(jqgrid);

        // init result string
        JSONObject resultObj = new JSONObject();
        com.mrd.gtimp.service.dto.Page remotePage = new com.mrd.gtimp.service.dto.Page(declarationInforms
                .getNumber() + 1, (int) declarationInforms.getTotalElements(), declarationInforms
                .getSize(), declarationInforms.getTotalPages());
        resultObj.put("page", remotePage);
        String configString = "id,declaration.id,declaration.businessId,confirmState,confirmTime|D,createTime|D,remark,customerCompany.id,customerCompany.name";
        JSONArray resultArray = JSONObjectBuilder
                .objectListToJsonArray(declarationInforms.getContent(), configString);// new
        resultObj.put("declarationInforms", resultArray);

        return resultObj.toString();
    }

    @Override
    public String validateConfirmInfrom(GtimpBaseBizQueryDTO qdto) throws Exception {
        String id = qdto.getId();
        DeclarationInform declarationInform = new DeclarationInform();
        declarationInform.setId(id);
        declarationInform.setConfirmerExt(qdto.getUserAccount());
        declarationInform.setConfirmState("1");
        declarationInform.setConfirmTime(new Date());
        List<String> properties = new ArrayList<String>();
        properties.add("confirmer");
        properties.add("confirmTime");
        properties.add("confirmState");
        declarationInformBiz.updateEntity(declarationInform, properties);
        msg = MsgConstants.OPERATION_SUCCESS;
        return msg;
    }

    public DeclarationInformBiz getDeclarationInformBiz() {
        return declarationInformBiz;
    }

    public void setDeclarationInformBiz(DeclarationInformBiz declarationInformBiz) {
        this.declarationInformBiz = declarationInformBiz;
    }

    @Override
    public String findBpk(GtimpBaseBizQueryDTO qdto) throws Exception {
        return null;
    }

    @Override
    public String processToBizEnd(GtimpBaseBizQueryDTO qdto) throws Exception {
        return doProcessMsgSend(qdto, BizProcessConstants.D_BIZ_END);
    }

    /**
     * 节点消息发送的具体实现方法
     *
     * @param processId ， 节点ID
     */
    private String doProcessMsgSend(GtimpBaseBizQueryDTO qdto, String processId) throws Exception {
        Declaration entity = null;
        if (StringUtils.isNotEmpty(qdto.getId())) {
            entity = declarationBiz.findEntityById(qdto.getId());
        } else if (StringUtils.isNotEmpty(qdto.getBpk())) {
            entity = declarationBiz.findEntityByBpk(qdto.getBpk().trim());
        } else {
            return MsgConstants.OPERATION_FAIL;
        }
        if (null != entity) {
            String supCompanyId = qdto.getSupId();
            String cusCompanyId = entity.getCustomer().getId();
            String args = entity.getId();
            try {
                sysMsgSendBiz.updateToSendMsg(processId, supCompanyId, cusCompanyId, args);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return MsgConstants.OPERATION_SUCCESS;
        }
        return MsgConstants.OPERATION_FAIL;
    }

    @Override
    public String processToCustomCheck(GtimpBaseBizQueryDTO qdto) throws Exception {
        return doProcessMsgSend(qdto, BizProcessConstants.D_CUSTOM_CHECK);
    }

    @Override
    public String processToCustomFree(GtimpBaseBizQueryDTO qdto) throws Exception {
        return doProcessMsgSend(qdto, BizProcessConstants.D_CUSTOM_FREE);
    }

    @Override
    public String processToCommodityCheck(GtimpBaseBizQueryDTO qdto) throws Exception {
        return doProcessMsgSend(qdto, BizProcessConstants.D_COMMODITY_CHECK);
    }

    @Override
    public String processToCommodityFree(GtimpBaseBizQueryDTO qdto) throws Exception {
        return doProcessMsgSend(qdto, BizProcessConstants.D_COMMODITY_FREE);
    }

    @Override
    public String containerStateFinish(GtimpTrailBizQueryDTO qdto) throws Exception {
        return null;
    }

    @Override
    public String confirmDeclarationNoBiz(String work_no, String sno) {
        System.out.println(work_no + "-" + sno);
        String sql = "update t_biz_declaration t set t.SNO='" + sno + "' where t.work_no='"
                + work_no + "'";
        System.out.println("更新报关单税号语句========" + sql);
        try {
            declarationBiz.updateBySql(sql);
            return "1";
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "0";
    }

}
